package com.wwl.cms.utils.designModeTest.proxy.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author wwl
 * @version 1.0
 * @date 2021/9/8 19:14
 * @description:
 */
public class ProxyFactory {
    private Object target;
    public ProxyFactory(Object target){
        this.target = target;
    }
    public Object getProxyInstance(){
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("jdk代理开始--");
                //通过反射机制调用目标对象的方法
                Object returnVal = method.invoke(target,args);
                System.out.println("JDK代理提交");
                return returnVal;
            }
        });
    }
}
